$(function () {
    obj.init();
});

var obj = new function () {
    return {
        dataGrid: null,
        dom: {
            search: null
        },
        init: function () {
            var schoolId = xhTool.getQuery('schoolId');
            this.dataGrid = new xhDataGrid($('#list'), 'res/getReferApplyDetail', {schoolId: schoolId});
            this.dataGrid.parseToolbar().init();
            this.dom.search = $('#bt_list_search');
            this.funObj().bindDataGridEvent();
            xhExtra.clearLoadSuccess(this.dataGrid);
            this.listener();
        },
        listener: function () {
            var $this = this;
            //查询
            $this.dom.search.click(function () {
                $this.funObj().search();
            });
            xhTool.bindDocKeyDown($this.dom.search);

        },
        funObj: function () {
            var $this = this;
            return {
                search: function () {
                    $this.dataGrid.reload({
                        search: {
                            vague: xhExtra.getValue($('#list_vague'))
                        }
                    })
                },
                bindDataGridEvent:function () {
                    $this.dataGrid.command({
                        view:detailview,
                        detailFormatter:function(index,row){
                            var str='<div class="ddv" style="padding:5px 0;overflow: auto;"  ><table style="width: 100%;height: 100%"  >';
                            if (row['teaNum'] !== 0){
                                content = '';
                                $.each(row['children'], function(index, row){
                                    content += '<tr><td>' + row.bookId + '</td><td>' + row.bookName;
                                });
                                str+='<tr><th width="45%">书id</th><th width="50%">书名</th></tr>' + content;
                            }
                            str+='</table></div>';
                            return str;

                        },
                        onExpandRow: function(index,row){
                            var ddv = $(this).datagrid('getRowDetail',index).find('div.ddv');
                            ddv.panel({
                                // height:200,
                                width:350,
                                border:false,
                                cache:false,
                                onLoad:function(){
                                    $this.dataGrid.command('fixDetailRowHeight',index);
                                    $this.dataGrid.command('fixDetailRowWidth',index);
                                }
                            });
                            $this.dataGrid.command('fixDetailRowHeight',index);
                        }
                    });
                }
            }
        }
    }
};

